package net.bwie.realtime.dy.dwd.log.funcation.zl.realtimegiftfuncation;

import net.bwie.realtime.dy.dwd.log.bean.TikTokBean;
import org.apache.flink.api.common.functions.AggregateFunction;

/**
 * @ClassName：GiftSumAggregator
 * @Author: ZddddQ
 * @Date: 2025/5/28 14:38
 * @Description: 必须描述类做什么事情, 实现什么功能
 */
public class GiftSumAggregator
     implements AggregateFunction<TikTokBean, Double, Double> {

    @Override
    public Double createAccumulator() {
        return 0.0; // 初始计数器为0
    }

    @Override
    public Double add(TikTokBean value, Double accumulator) {
        //每条数据+=礼物价值
        if ("gift".equals(value.getEventType())) {
             accumulator += 1.0*value.getGiftValue();
        }
        else accumulator += 0.0;

        return accumulator;

    }

    @Override
    public Double getResult(Double accumulator) {
        return accumulator;
    }

    @Override
    public Double merge(Double a, Double b) {
        return a+b;
    }
}
